package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.business.domain.CcChukuDetail;
import com.lxmes.system.service.ISysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.business.domain.CcChukuInfo;
import com.lxmes.business.service.ICcChukuInfoService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 出库单Controller
 *
 * @author 张志煜
 * @date 2022-11-27
 */
@Api(tags="出库单管理")
@RestController
@RequestMapping("/business/chukuInfo")
public class CcChukuInfoController extends BaseController
{
    @Autowired
    private ICcChukuInfoService ccChukuInfoService;
    @Autowired
    private ISysDictDataService dictDataService;
    /**
     * 查询出库单列表
     */
    @ApiOperation(value="出库单列表")
    @PreAuthorize("@ss.hasPermi('business:chukuInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CcChukuInfo ccChukuInfo)
    {
        startPage();
        List<CcChukuInfo> list = ccChukuInfoService.selectCcChukuInfoList(ccChukuInfo);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('business:chukuInfo:mainList')")
    @GetMapping("/mainList")
    public TableDataInfo mainList(CcChukuInfo ccChukuInfo)
    {
        startPage();
        List<CcChukuInfo> list = ccChukuInfoService.selectCcChukuInfoMainList(ccChukuInfo);
        return getDataTable(list);
    }
    /**
     * 查询出库结算单列表
     */
    @ApiOperation(value="出库结算单列表")
    @PreAuthorize("@ss.hasPermi('business:chukuInfo:jiesuanList')")
    @GetMapping("/jiesuanList")
    public TableDataInfo jiesuanList(CcChukuInfo ccChukuInfo)
    {
        startPage();
        List<CcChukuInfo> list = ccChukuInfoService.selectCcChukuInfoJieSuanList(ccChukuInfo);
        return getDataTable(list);
    }
    //流转出库查询
    @GetMapping("/liuzhuanList")
    public TableDataInfo liuzhuanList(CcChukuInfo ccChukuInfo)
    {
        startPage();
        List<CcChukuInfo> list = ccChukuInfoService.selectCcChukuInfoLzList(ccChukuInfo);
        return getDataTable(list);
    }
    /**
     * 导出出库单列表
     */
    @PreAuthorize("@ss.hasPermi('business:chukuInfo:export')")
    @Log(title = "出库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CcChukuInfo ccChukuInfo)
    {
        List<CcChukuInfo> list = ccChukuInfoService.selectCcChukuInfoList(ccChukuInfo);
        ExcelUtil<CcChukuInfo> util = new ExcelUtil<CcChukuInfo>(CcChukuInfo.class);
        util.exportExcel(response, list, "出库单数据");
    }

    /**
     * 获取出库单详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:chukuInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ccChukuInfoService.selectCcChukuInfoById(id));
    }

    @GetMapping(value = "/handleAccount/{ids}")
    public AjaxResult handleAccount(@PathVariable("ids") Long[] ids)
    {
        return AjaxResult.success(ccChukuInfoService.handleAccount(ids));
    }

    @GetMapping(value = "/handleSummary/{ids}")
    public AjaxResult handleSummary(@PathVariable("ids") Long[] ids)
    {
        return AjaxResult.success(ccChukuInfoService.handleSummary(ids));
    }

    /**
     * 新增出库单
     */
    @PreAuthorize("@ss.hasPermi('business:chukuInfo:add')")
    @Log(title = "出库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CcChukuInfo ccChukuInfo)
    {
        return toAjax(ccChukuInfoService.insertCcChukuInfo(ccChukuInfo));
    }
    /**
     * 新增扫码出库
     */
    @ApiOperation(value="扫码出库")
    @PreAuthorize("@ss.hasPermi('business:chukuInfo:add')")
    @Log(title = "出库单扫码出库", businessType = BusinessType.INSERT)
    @PostMapping("/mobileSmAdd")
    public AjaxResult mobileSmAdd(CcChukuInfo ccChukuInfo)
    {
        return toAjax(ccChukuInfoService.insertSmCcChukuInfo(ccChukuInfo));
    }


    @ApiOperation(value="获取出库类型")
    @GetMapping("/getDictDataCuKuType")
    public AjaxResult getDictDataCuKuType(){
        return AjaxResult.success( dictDataService.selectDictDataByType("chuku_type"));
    }
    /**
     * 添加出库库存物料
     */
    @GetMapping("/addChuKuStockinfo/{ids}")
    public AjaxResult addChuKuStockinfo(@PathVariable Long[] ids)
    {
        List<CcChukuInfo> list = ccChukuInfoService.addChuKuStockinfo(ids);
        return AjaxResult.success(list);
    }
    /**
     * 获取出库任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:chukuInfo:zhixing')")
    @GetMapping(value = "/zhixingChuku/{ids}")
    public AjaxResult zhixingChuku(@PathVariable Long[] ids)
    {
        return AjaxResult.success(ccChukuInfoService.zhixingChuku(ids));
    }
    /**
     * 修改出库单
     */
    @PreAuthorize("@ss.hasPermi('business:chukuInfo:edit')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CcChukuInfo ccChukuInfo)
    {
        return toAjax(ccChukuInfoService.updateCcChukuInfo(ccChukuInfo));
    }

    /**
     * 撤销出库单
     */
    @PreAuthorize("@ss.hasPermi('business:chukuInfo:remove')")
    @Log(title = "出库单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ccChukuInfoService.deleteCcChukuInfoByIds(ids));
    }
    /**
     * 删除出库单
     */
    @PreAuthorize("@ss.hasPermi('business:chukuInfo:remove')")
    @Log(title = "出库单", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}")
    public AjaxResult remove2(@PathVariable Long[] ids)
    {
        return toAjax(ccChukuInfoService.deleteCcChukuInfoByIds2(ids));
    }
}
